<?php
/**
 * Created by PhpStorm.
 * User: hui
 * Date: 16/8/1
 * Time: 20:59
 */
namespace app\index\model;

use think\Db;
use think\Loader;
use think\Model;
use think\Request;

class Member extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'u_member';

    // 设置当前模型的数据库连接
    protected $connection = 'db_config2';

    public function set_user()
    {
        $find = new Find;
        $uuid = $find->get_uuid();
        $post = Request::instance()->post();
        $data['Birthday'] = date('Y-m-d H:i:s', strtotime($post['Birthday']));
        $data['ViewBirthday'] = date('Y年m月d日', strtotime($post['Birthday']));
        $data['Mobile'] = $post['Mobile'];
        $data['Email'] = $post['Email'];
        $data['QQ'] = $post['QQ'];
        $data['Age'] = $post['Age'];
        $data['Sex'] = $post['Sex'];
        $res = $this->validate('Member.edit')->save($data, ['ID' => $uuid]);
        if ($res === false) {
            return $res = $this->getError();
        } elseif ($res === 0) {
            return '个人信息没有变动';
        } else {
            return '更新个人信息成功';
        }
    }

    public function card()
    {
        return $this->hasOne('Card', 'ID', 'CardID');
    }
}